package com.ruan.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruan.entity.R;
import com.ruan.entity.User;
import com.ruan.query.UserQuery;
import com.ruan.service.UserService;
import com.ruan.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName:UserController
 * @Author:阮昇
 * @Description:
 * @Datetime: 2023/9/18 10:45
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/uploadAvatar")
    @PreAuthorize("hasAuthority('uploadAvatar')")
    public R<String> uploadAvatar(MultipartFile file){
        return userService.uploadAvatar(file);
    }

    @RequestMapping("/getUserById")
    @PreAuthorize("hasAuthority('getUserById')")
    public R<User> getUserById(String id){
        return userService.getUserById(id);
    }

    @RequestMapping("/editUser")
    @PreAuthorize("hasAuthority('editUser')")
    public R<Void> editUser(UserVo userVo){
        return userService.editUser(userVo);
    }

    @RequestMapping("/getUserList")
    @PreAuthorize("hasAuthority('getUserList')")
    public R<IPage<User>> getUserList(UserQuery userQuery){
        return userService.getUserList(userQuery);
    }
}
